<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <title>网站设置</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="/static/layadmin/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="/static/layadmin/style/admin.css" media="all">
</head>

<body>
    <div class="layui-fluid">
        <div class="layui-row layui-col-space15">
            <div class="layui-col-md12">
                <div class="layui-card">
                    <!-- <div class="layui-card-header">新增菜单</div> -->
                    <div class="layui-card-body" pad15>
                        <div class="layui-form" wid100 lay-filter="">
                            <div class="layui-form-item">
                                <label class="layui-form-label">栏目名称<span style="color: red;">*</span></label>
                                <div class="layui-input-block">
                                    <input type="text" name="name" value="{$mess.name}" class="layui-input" lay-verify="required">
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <label class="layui-form-label">上级<span style="color: red;">*</span></label>
                                <div class="layui-input-inline">
                                    <select name="pid" lay-verify="required">
                                        <option value="0">顶级菜单</option>
                                        {volist name="channel" id="v"}
                                        <option value="{$v.id}" {if condition="$mess.pid eq $v.id" } selected="selected" {/if} {if condition="$v.level eq 1" } disabled="disabled" {/if} {if condition="$mess.id eq $v.id" } disabled="disabled" {/if}>{$v.name} </option> {volist name="$v.child" id="y" } <option value="{$y.id}" {if condition="$mess.pid eq $y.id" } selected="selected" {/if} {if condition="$v.level eq 2" } disabled="disabled" {/if} {if condition="$mess.id eq $y.id" } disabled="disabled" {/if}>|-----{$y.name} </option> {/volist} {/volist} </select> </div> <div class="layui-form-mid layui-word-aux">最多添加三级栏目</div>
                            </div>
                            <div class="layui-form-item">
                                <label class="layui-form-label">模型<span style="color: red;">*</span></label>
                                <div class="layui-input-inline">
                                    <select name="modelx" lay-verify="required" lay-filter="modelx">
                                        <option value="">请选择模型</option>
                                        {volist name="modelx" id="v"}
                                        <option value="{$v.id}" {if condition="$mess.modelx eq $v.id" }selected="selected" {/if}>{$v.name} </option> {/volist} </select> </div> <div class="layui-form-mid layui-word-aux">URL模型为外链，不生成后台菜单</div>
                            </div>
                            <div class="layui-form-item">
                                <label class="layui-form-label">模板页<span style="color: red;">*</span></label>
                                <div class="layui-input-inline">
                                    <select name="template" lay-verify="required" id="template">
                                        <option value="">请选择模板页</option>
                                        {volist name="temp" id="v"}
                                        <option value="{$v.id}" {if condition="$mess.template eq $v.id" }selected="selected" {/if}>{$v.vpage}——{$v.name} </option> {/volist} </select> </div> <!-- <div class="layui-form-mid layui-word-aux">选择URL模型时无模板页</div> -->
                            </div>
                            <div class="layui-form-item">
                                <label class="layui-form-label">网址</label>
                                <div class="layui-input-inline">
                                    <input type="text" name="website" value="{$mess.website}" class="layui-input">
                                </div>
                                <div class="layui-form-mid layui-word-aux">选择URL模型时必填</div>
                            </div>
                            <div class="layui-form-item">
                                <label class="layui-form-label">页面banner</label>
                                <div class="layui-input-inline" style="width:30%;">
                                    <input type="text" name="thumb" id="filepath" value="{$mess.thumb}" class="layui-input">
                                    <!-- <input type="hidden" name="annexes">                                  -->
                                </div>
                                <div class="layui-form-mid layui-word-aux" style="padding:0px !important;">
                                    <button type="button" class="layui-btn" id="test-upload-type1"><i class="layui-icon"></i>上传图片</button>
                                </div>
                                <!-- <div class="layui-form-mid layui-word-aux">仅支持上传pdf格式</div> -->
                            </div>
                            <div class="layui-form-item layui-form-text">
                                <label class="layui-form-label">简介</label>
                                <div class="layui-input-block">
                                    <textarea name="summary" class="layui-textarea">{$mess.summary}</textarea>
                                </div>
                            </div>
                            <div class="layui-form-item layui-form-text">
                                <label class="layui-form-label">详情</label>
                                <div class="layui-input-block" id="wangEditor">{$mess.content}
                                    <!-- <textarea name="content" id="content" class="layui-textarea" lay-verify="required">{$mess.content}</textarea> -->
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <label class="layui-form-label">排序</label>
                                <div class="layui-input-inline" style="width: 80px;">
                                    <input type="text" name="sort" lay-verify="number" value="{$mess.sort|default=9999}" class="layui-input">
                                    <input type="hidden" name="updid" value="{$mess.id}">
                                </div>
                                <!-- <div class="layui-form-mid layui-word-aux">本地开发一般推荐设置为 0，线上环境建议设置为 10。</div> -->
                            </div>
                            <div class="layui-form-item">
                                <div class="layui-input-block">
                                    <button class="layui-btn" lay-submit lay-filter="formSubmit">确认保存</button>
                                    <button class="layui-btn layui-btn-primary formCancel">取消</button>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <script src="/static/layadmin/layui/layui.js"></script>
    <script src="/static/plugins/editor/wangeditor/dist/wangEditor.min.js"></script>
    <script>
      const E = window.wangEditor;//初始化
        const editor = new E('#wangEditor');//实例化
        editor.config.height = 500;//编辑器高度
        editor.config.pasteFilterStyle = false;//取消粘贴内容格式过滤
        editor.config.uploadImgServer = '/admin/base/upload_file';//上传文件接口
        editor.config.uploadFileName = 'file';//上传文件名
        editor.config.uploadImgMaxLength = 1; 
        editor.config.uploadVideoServer = '/admin/base/upload_video';//上传视频接口
        editor.config.uploadVideoMaxSize = 50 * 1024 * 1024;  // 50m，上传视频大小
        editor.config.uploadVideoAccept = ['mp4'];//上传视频格式
        editor.config.uploadVideoName = 'videox';//上传视频名
        editor.create();
    layui.config({
        base: '/static/layadmin/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index', 'form', 'upload'], function() {
        var $ = layui.$,
            upload = layui.upload,
            form = layui.form;

        //监听提交
        form.on('submit(formSubmit)', function(data) {
            var field = data.field; //获取提交的字段
            var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引  
            // layer.msg('表单已提交');
            // var thumb = $("#filepath").attr("subId");
            // console.log(field);
            var content=editor.txt.html();
            //提交 Ajax 成功后，关闭当前弹层并重载表格
            $.post('/admin/systemt/addChannelDone/updid/' + field.updid, { name: field.name, pid: field.pid, modelx: field.modelx, template: field.template, website: field.website, thumb: field.thumb, summary: field.summary, content:content, sort: field.sort }, function(res) {
                res = $.parseJSON(res);
                console.log(res.code);
                if (res.code == 200) {
                    layer.msg(res.msg, {
                        icon: 1,
                        time: 2000 //2秒关闭（如果不配置，默认是3秒）
                    }, function() {
                        // parent.layui.table.reload('list-table'); //重载表格
                        parent.location.reload();
                        parent.layer.close(index); //再执行关闭 
                    });
                } else {
                    layer.msg(res.msg, { icon: 2, time: 2000 });
                }
            });
        });
        $('.formCancel').on('click', function() {
            var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引  
            parent.layer.close(index); //再执行关闭 
        });


        $('#filepath').on('click', function() {

            var thumb = $(this).val();
            if (thumb) {
                window.open(thumb);
            }
        });
        form.on('select(modelx)', function(data) {
            // var modelx=data.value;
            $.get('{:url("admin/systemt/getTemp")}', { modelx: data.value }, function(data) {
                data = $.parseJSON(data);
                // console.log(ret);

                if (data) {
                    var html1 = '<dd lay-value="" class="layui-select-tips layui-this">选择模板页</dd>';
                    var html2 = '<option value="" >选择模板页</option>';
                    for (var i = 0; i < data.length; i++) {
                        html1 += '<dd lay-value="' + data[i].id + '">' + data[i].vpage + '——' + data[i].name + '</dd>';
                        html2 += '<option value="' + data[i].id + '">' + data[i].vpage + '——' + data[i].name + '</option>';
                    }
                    $("#template").next().children().eq(1).html(html1);
                    $("#template").html(html2);
                    form.render();

                } else {
                    layer.msg("该模型下没有模板页", { icon: 5 })
                }
            });

            // console.log(data.elem); //得到select原始DOM对象
            // console.log(data.value); //得到被选中的值
            // console.log(data.othis); //得到美化后的DOM对象
        });
        var uploadInst = upload.render({
            elem: '#test-upload-type1',
            url: '/admin/base/default_upload', //改成您自己的上传接口
            accept: 'file',
            // acceptMime:'application/msword,image/gif,image/x-icon,image/jpeg,video/mpeg4,application/pdf,application/x-png,application/x-ppt,application/x-xls,application/x-ico,audio/mp3,image/png,application/vnd.ms-powerpoint,application/x-ppt,text/plain,application/vnd.ms-excel' ,
            acceptMime: 'image/jpeg,image/gif,image/png,image/x-icon',
            size: 2048, //限制文件大小，单位 KB
            before: function(obj) {
                //预读本地文件示例，不支持ie8
                obj.preview(function(index, file, result) {

                    var point = file.type.lastIndexOf("/");

                    var type = file.type.substr(point + 1);
                    console.log(file);
                    // console.log(type);

                    // $('#showfile').html('<img src="' + result + '">');


                    // $('#demo1').attr('src', result); //图片链接（base64）
                });
            },
            done: function(res) {
                // console.log(res);
                if (res.code > 0) {
                    layer.msg(res.msg, { icon: 6 }, function() {
                        $('#filepath').val(res.filename);
                    });
                } else {
                    return layer.msg('上传失败');
                }
                //上传成功
            },
            error: function() {
                //演示失败状态，并实现重传
                var demoText = $('#demoText');
                demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-xs demo-reload">重试</a>');
                demoText.find('.demo-reload').on('click', function() {
                    uploadInst.upload();
                });
            }
        });
    })
    </script>
</body>

</html>